package com.alex.algorithm.easy;

/**
 * sorted array
 */
public class TwoSum2 {

    public static void main(String[] args) {
        int[] indexes = getTwoIndex(new int[]{2,7,11}, 13);
        if (indexes != null) {
            System.out.println(indexes[0]);
            System.out.println(indexes[1]);
        }
    }

    public static int[] getTwoIndex(int[] numbers, int target) {
        int[] indexes = null;
        int left = 0;
        int right = numbers.length - 1;
        while(left < right) {
            int curSum = numbers[left] + numbers[right];
            if (curSum > target) {
                --right;
            }else if(curSum < target) {
                ++left;
            }else {
                indexes = new int[]{left+1, right+1};
                break;
            }
        }
        return  indexes;
    }
}
